﻿package com.vinyl.utils 
{
	/**
	 * ...
	 * @author vi-nyl
	 */
	public class ToString
	{
		public static function toCurrencyFormat( num:Number, separator:String=",", unit:int=3):String 
		{
			var sign:String = num < 0 ? "-":"";
			var myAmount:String = String(Math.abs(num));
			if (myAmount.length > 0) {
				var tempAmount:String = "";
				var j:Number = -1;
				for (var i:Number = myAmount.length; i>=0; i--) {
					if (j != 0 && j%unit == 0) {
						tempAmount = myAmount.charAt(i)+separator+tempAmount;
					} else {
						tempAmount = myAmount.charAt(i)+tempAmount;
					}
					j++;
				}
			}
			return sign+tempAmount;
		}
		
		public static function toNumberFormat( str ):Number
		{
			var spl = str.split( "," );
			var rstStr = "";
			for( var i = 0; i < spl.length; i++ )
			{
				rstStr = rstStr + spl[i];
			}
			return Number( rstStr );
		}
		
	}

}